import { _decorator, Component, Node,Sprite,Label,Rect,Vec3,Vec2 } from 'cc';
import {GameMain} from "../GameMain";
import {LineGameEditor} from "./LineGameEditor";
import {GameConfig} from "../GameConfig";
const { ccclass, property } = _decorator;

@ccclass('EditorBall')
export class EditorBall extends Component {

    public ballSprite:Sprite=null;
    public label:Label=null;

    //val同时也代表颜色id
    public val:number=0;

    public idx:number=0;
    public subIdx:number=0;

    public rect:Rect=new Rect(0,0,0,0);

    public inited:boolean=false;

    onLoad()
    {
        this.init();
    }

    public init()
    {
        this.ballSprite=this.node.getChildByName("scale").getChildByName("ballSprite").getComponent(Sprite);
        this.label=this.node.getChildByName("Label").getComponent(Label);
        this.initRect();
        this.inited=true;
    }

    public initRect()
    {

    }

    public isInRect(p:Vec2):boolean
    {
        let w:number=80;
        let pos:Vec3=this.node.getPosition();
        this.rect.x=pos.x - w*0.5;
        this.rect.y=pos.y -w*0.5;
        this.rect.width=w;
        this.rect.height=w;

        return this.rect.contains(p);
    }

    start() {

    }

    public setVal(v:number)
    {
        if(this.inited===false)
            this.init();
        this.val=v;
        this.ballSprite.spriteFrame=LineGameEditor.instance.getBallSpriteFrame(this.val);
    }

    public setIdx(id0:number, id1:number)
    {
        if(this.inited===false)
            this.init();
        this.idx=id0;
        this.subIdx=id1;
        this.label.string=""+this.idx+"-"+this.subIdx;
    }

    public updateIdx(id:number)
    {
        this.idx=id;
        this.label.string=""+this.idx+"-"+this.subIdx;
    }

    update(deltaTime: number) {
        
    }
}

